package guava.multimap;

import com.google.common.collect.ArrayListMultimap;

import java.util.List;
import java.util.Map;

/**
 * Created by ZhuQianli on 2018/1/26.
 */
public class App {
    /**
     * Map<K, V>
     * 实现              	   键行为类似	        值行为类似
     * ArrayListMultimap	   HashMap	        ArrayList
     * HashMultimap	           HashMap	        HashSet
     * LinkedListMultimap	   LinkedHashMap	LinkedList
     * LinkedHashMultimap      LinkedHashMap	LinkedHashMap
     * TreeMultimap	           TreeMap	        TreeSet
     * ImmutableListMultimap   ImmutableMap	    ImmutableList (不可变的集合 浅不可变)
     * ImmutableSetMultimap    ImmutableMap	    ImmutableSet
     */
    public static void main(String[] args) {
        int expectedKeys = 5;
        int expectedValuesPerKey = 20;

        ArrayListMultimap multimap = ArrayListMultimap.create(expectedKeys, expectedValuesPerKey);

        String age = "10";
        String name = "1";
        multimap.put(age, name);
        multimap.put(age, name);
        multimap.put(age, name);
        // key不存在返回空的List
        List list = multimap.get("2");
        System.out.println(list);


        // asMap后不允许put key不存在返回null
        Map map = multimap.asMap();
        Object list2 = map.get("2");
        System.out.println(list2);
        try {
            map.put(age, name);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }



}
